﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Graphics;
using Terraria.GameContent.UI.Elements;
using Terraria.UI;

namespace Terraria.ModLoader.UI
{
	// Token: 0x02000279 RID: 633
	internal class UIColorTextPanel : UIPanel
	{
		// Token: 0x060019FA RID: 6650 RVA: 0x00012631 File Offset: 0x00010831
		public UIColorTextPanel(string text, Color color, float textScale = 1f, bool large = false)
		{
			this.SetText(text, textScale, large);
			this.SetColor(color);
		}

		// Token: 0x060019FB RID: 6651 RVA: 0x0001266B File Offset: 0x0001086B
		public override void Recalculate()
		{
			this.SetText(this._text, this._textScale, this._isLarge);
			base.Recalculate();
		}

		// Token: 0x060019FC RID: 6652 RVA: 0x00427244 File Offset: 0x00425444
		public void SetText(string text, float textScale, bool large)
		{
			DynamicSpriteFont dynamicSpriteFont = large ? Main.fontDeathText : Main.fontMouseText;
			Vector2 vector = new Vector2(dynamicSpriteFont.MeasureString(text).X, large ? 32f : 16f) * textScale;
			this._text = text;
			this._textScale = textScale;
			this._textSize = vector;
			this._isLarge = large;
			this.MinWidth.Set(vector.X + this.PaddingLeft + this.PaddingRight, 0f);
			this.MinHeight.Set(vector.Y + this.PaddingTop + this.PaddingBottom, 0f);
		}

		// Token: 0x060019FD RID: 6653 RVA: 0x0001268B File Offset: 0x0001088B
		public void SetColor(Color color)
		{
			this._color = color;
		}

		// Token: 0x060019FE RID: 6654 RVA: 0x004272EC File Offset: 0x004254EC
		protected override void DrawSelf(SpriteBatch spriteBatch)
		{
			base.DrawSelf(spriteBatch);
			CalculatedStyle innerDimensions = base.GetInnerDimensions();
			Vector2 pos = innerDimensions.Position();
			if (this._isLarge)
			{
				pos.Y -= 10f * this._textScale;
			}
			else
			{
				pos.Y -= 2f * this._textScale;
			}
			pos.X += (innerDimensions.Width - this._textSize.X) * 0.5f;
			if (this._isLarge)
			{
				Utils.DrawBorderStringBig(spriteBatch, this._text, pos, this._color, this._textScale, 0f, 0f, -1);
				return;
			}
			Utils.DrawBorderString(spriteBatch, this._text, pos, this._color, this._textScale, 0f, 0f, -1);
		}

		// Token: 0x04001754 RID: 5972
		private string _text = "";

		// Token: 0x04001755 RID: 5973
		private Color _color;

		// Token: 0x04001756 RID: 5974
		private float _textScale = 1f;

		// Token: 0x04001757 RID: 5975
		private Vector2 _textSize = Vector2.Zero;

		// Token: 0x04001758 RID: 5976
		private bool _isLarge;
	}
}
